<?php

namespace IDock\Insurance\ZMBX\Response;

use IDock\Http\Response;
use IDock\Insurance\ZMBX\Response\AllZMBXResponse;
use IDock\Printer\EPolicyDownloadPrinter;

class EPolicyDownloadResponse extends AllZMBXResponse
{

    /**
     * @var EPolicyDownloadPrinter $printer
     */
    public $printer = EPolicyDownloadPrinter::class;

    public function printerInit(): Response
    {
        if ($this->printer->doing) {
            return $this;
        }
        $body = $this->getBody();
        $status = $body['statusCode'] ?? '0';
        $this->printer->url = $body['downloadUrl'][0] ?? '';
        if($status == '0' or empty($this->printer->url)){
            $this->printer->finish = false;
            $this->printer->doing = true;
            return $this;
        }
        $this->printer->doing = false;
        $this->printer->finish = true;
        return $this;
    }
}
